/**
 *  This file is part of Zero2D.
 *
 *  Zero2D is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Zero2D is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Zero2D.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "MatrixStack.h"

MatrixStack::MatrixStack(size_t inCapacity) : mCapacity(inCapacity), mSize(1)
{
    if (mCapacity < 2) mCapacity = 2;
    mMatrices = new Matrix3D[mCapacity];
}

MatrixStack::~MatrixStack()
{
    delete [] mMatrices;
}

void MatrixStack::push()
{
    if (mSize < mCapacity)
    {
        mMatrices[mSize] = mMatrices[mSize - 1];
        ++mSize;
    }
}

void MatrixStack::pop()
{
    if (mSize > 1) --mSize;
}

void MatrixStack::reset()
{
    mSize = 1;
    mMatrices[0].loadIdentity();
}
